package com.cyf.db.mapper;

import com.cyf.db.bean.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * app用户
 * Created by cage on 2017/2/16.
 */

public interface UserMapper {

    @Insert("insert into users(mobile, createdTime, token, username, userAuth) " +
            "values(#{user.mobile}, #{user.createdTime}, #{user.token}, #{user.username}, #{user.userAuth})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "user.id", resultType = int.class, before = false)
    void insertUser(@Param("user") User user);

    @Select("select * from users where mobile = #{mobile}")
    User getByMobile(@Param("mobile") String mobile);

    @Select("select * from users where token = #{token}")
    User getByToken(@Param("token") String token);

    // 更新app用户的Android版本信息
    @Update("update users set version = #{appUser.version} where id = #{appUser.id}")
    void updateVersion(@Param("appUser") User user);

    // 更新app用户的Ios版本信息
    @Update("update users set iosVersion = #{iosVersion} where id = #{id}")
    void updateIosVersion(@Param("iosVersion") String version, @Param("id") Integer id);

    @Update("update users set portraitPath = #{portraitPath} where id = #{id}")
    void updatePortraitPath(@Param("portraitPath") String portraitPath, @Param("id") Integer id);

    @Select("select * from users where id = #{id}")
    User getById(@Param("id") Integer id);

    // 更新用户的eb
    @Update("update users set ebBalance = #{eb} where id = #{id}")
    void updateEb(@Param("eb") int eb, @Param("id") Integer id);

    // 需要发送人管平台短信通知的
    @Select("select * from users where sendStatisMsg = 1")
    List<User> getNeedSendStatisDataUsers();

    @Update("update users set token = #{token} where id = #{id}")
    void updateToken(@Param("token") String token, @Param("id") Integer id);

    // app注册（手机号已在adps等上注册）
    @Update("update users set token = #{user.token}, userAuth = #{user.userAuth} where id = #{user.id}")
    void updateAppInfo(@Param("user") User user);

    @Update("update users set userAuth = #{userAuth} where id = #{id}")
    void updateUserAuthById(@Param("userAuth") int userAuth, @Param("id") Integer id);
}
